package de.previsor.workflow;

import de.previsor.workflow.control.RootController;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
/***
 * Startpunkt des Programmes "Previsor"
 * Baut das Grundlayout mit Loginfläche auf.
 * @author Robert Keller
 */
public class MainApp extends Application {

    private static Stage primaryStage;
    public static BorderPane rootLayout;

    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("Previsor");

        initRootLayout();
        showLogin();
    }

    /**
     * Initializes the root layout.
     */
    public void initRootLayout() {
        try {
           
            // Load root layout from fxml file.
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("view/RootLayout.fxml"));
            rootLayout = (BorderPane) loader.load();

            // Show the scene containing the root layout.
            Scene scene = new Scene(rootLayout);         
            primaryStage.setScene(scene);
            primaryStage.setResizable(false);
            primaryStage.show();
            
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void showLogin() {
        try {
            // Load person overview.
            FXMLLoader loader = new FXMLLoader();
            
            loader.setLocation(MainApp.class.getResource("view/Login.fxml"));
            AnchorPane login = (AnchorPane) loader.load();
            
            // Set person overview into the center of root layout.
           
            rootLayout.setCenter(login);
            //changeView();
        } catch (IOException e) {
            //e.printStackTrace();
            System.out.println("Oberfläche \"Login\" konnte nicht geladen werden!");
        }
    }
    /**
     * Shows the asset overview inside the root layout.
     */
    public static void showPrevisorUiWorkflow() {
        try {
            // Load person overview.
            FXMLLoader loader = new FXMLLoader();
            
            loader.setLocation(MainApp.class.getResource("view/Previsor_UI_Workflow.fxml"));
            AnchorPane assetOverview = (AnchorPane) loader.load();
            
            // Set person overview into the center of root layout.
            rootLayout.setCenter(assetOverview);
            //changeView();
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Oberfläche \"Previsor UI\" konnte nicht geladen werden!");
        }
    } 
    
        /**
     * Shows the asset overview inside the root layout.
     */
    public static void showPrevisorUiAsset() {
        try {
            // Load person overview.
            FXMLLoader loader = new FXMLLoader();
            
            loader.setLocation(MainApp.class.getResource("view/Previsor_UI_Asset.fxml"));
            AnchorPane assetOverview = (AnchorPane) loader.load();
            
            // Set person overview into the center of root layout.
            rootLayout.setCenter(assetOverview);
            //changeView();
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Oberfläche \"Previsor Asset UI\" konnte nicht geladen werden!");
        }
    } 

    /**
     * Returns the main stage.
     * @return : Stage Datatyp
     */
    public static Stage getPrimaryStage() {
        return primaryStage;
    }

    public static void main(String[] args) {
        launch(args);
    }
}
